package com.pennywise.mapper;

import com.pennywise.model.Reminder;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReminderMapper {
    
    @Insert("""
        INSERT INTO reminder (title, content, reminder_time, is_active, create_time, update_time)
        VALUES (#{title}, #{content}, #{reminderTime}, #{isActive}, #{createTime}, #{updateTime})
    """)
    void insert(Reminder reminder);
    
    @Select("SELECT * FROM reminder WHERE id = #{id}")
    Reminder findById(Long id);
    
    @Update("""
        UPDATE reminder SET
        title = #{title},
        content = #{content},
        reminder_time = #{reminderTime},
        is_active = #{isActive},
        update_time = #{updateTime}
        WHERE id = #{id}
    """)
    void update(Reminder reminder);
    
    @Delete("DELETE FROM reminder WHERE id = #{id}")
    void deleteById(Long id);
    
    @Select("""
        SELECT * FROM reminder 
        WHERE is_active = true 
        AND reminder_time <= #{currentTime}
        AND reminder_time > #{lastCheckTime}
    """)
    List<Reminder> findDueReminders(LocalDateTime currentTime, LocalDateTime lastCheckTime);
} 